package com.company.service.impl;

import com.company.model.Banner;
import com.company.model.Company;
import com.company.model.SortType;
import com.company.model.request.BannerQuery;
import com.company.model.request.CompanyQuery;
import com.company.model.result.HomeResult;
import com.company.model.result.PageResult;
import com.company.service.IBannerService;
import com.company.service.ICacheService;
import com.company.service.ICompanyService;
import com.company.service.IHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by tu on 2017/7/11.
 */
@Service
public class HomeServiceImpl implements IHomeService {

  @Autowired
  IBannerService bannerService;
  @Autowired
  ICompanyService companyService;
  @Autowired
  ICacheService cacheService;

  @Override
  public HomeResult home() {
    HomeResult homeResult;
    PageResult<Banner> banners = bannerService.list(new BannerQuery());

    CompanyQuery newQuery = new CompanyQuery();
    newQuery.setSort(SortType.NEW.sort);
    newQuery.setPageSize(10);
    PageResult<Company> newest = companyService.list(newQuery);

    CompanyQuery buryQuery = new CompanyQuery();
    buryQuery.setSort(SortType.BURY.sort);
    buryQuery.setPageSize(5);
    PageResult<Company> buries = companyService.list(buryQuery);

    CompanyQuery diggQuery = new CompanyQuery();
    diggQuery.setSort(SortType.DIGG.sort);
    diggQuery.setPageSize(5);
    PageResult<Company> diggs = companyService.list(diggQuery);

    homeResult = new HomeResult(banners.getContent(), newest.getContent(), diggs.getContent(),
        buries.getContent());
    return homeResult;
  }
}
